<template>
  <div class="form-layout">
    <!--左侧导航-->
    <div class="nav-left">
      <customAnchor :itemList="[{ name: 'box-base', title: '基础信息' }]" />
    </div>
    <!--表单区域-->
    <div class="form-right" ref="formRight">
      <customForm :data="form" :rules="propRules" ref="editForm" :disabled="propReadonly">
        <template #content>
          <div id="box-base" class="box-title">基础信息</div>
          <customFormItem label="机构名称" name="name" :parent="_self" :form="form" />
          <customFormItem label="机构类型" name="type" :parent="_self" :form="form"
                          :clearable="false"
                          :type="constCommon.formItemType.selectDict.name"
                          :config="{dictType: constCommon.dictType.officeType}" />
          <customFormItem label="排序" name="sort" :parent="_self" :form="form"
                          :type="constCommon.formItemType.inputNumber.name" :config="{ defaultValue: 1}"   />
          <customFormItem label="识别码" name="code" :parent="_self" :form="form" />

        </template>
      </customForm>
    </div>
  </div>
</template>

<script>
import customAnchor from '@/components/custom/form/customAnchor.vue'

export default {
  help: '机构管理-详情',
  data() {
    return {
      form: {},
      viewData: {},
    }
  },
  methods: {
  },
  created() {
    this.$emit('event-register', {
      validate: (callback) => {
        return this.$refs.editForm.validate(callback)
      },
      beforeSave: () => {
        this.$emit('data-callback', this.form)
        return true
      },
      afterMove: (formData, initData) => {
        this.form = global.utils.jsonClone(formData)
        this.viewData = this.propCurrentRow;
        // 新增时需要填写父级机构的id和名称
        if (!this.form.id) {
          this.form.parentId = (initData && initData.id) ? initData.id : "0"
          this.$set(this.viewData, 'parentName', (initData && initData.title)? initData.title : "组织机构")
        } else {
          let wrapper = this.$newWrapper().eq('office_id', this.form.id)
        }
        this.$set(this.form, 'id', this.form.id)
      },
      afterSave: () => {
      },
      beforeDelete: () => {
        return true
      },
      afterDelete: () => {
      },
      beforeFlow: (flowButtonKey) => {
        return true
      },
      afterFlow: (flowButtonKey) => {
      },
      beforeClose: () => {
        return true
      },
    })
  },
  props: {
    propParent: Object,
    propInitData: Object,
    propPrimaryKey: String,
    propDictionaries: Object,
    propCurrentRow: Object,
    propViewFormData: Object,
    propReadonly: Boolean,
    propStatus: String,
    propRules: Object,
  },
  components: { customAnchor },
  computed: {},
}
</script>
